// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include "GameplayTagContainer.h"
#include "UObject/SoftObjectPath.h"
#include "UObject/WeakObjectPtr.h"

#include "LyraContextEffectsLibrary.generated.h"

#define UE_API LYRAGAME_API

class UNiagaraSystem;
class USoundBase;
struct FFrame;

/**
 * 上下文效果库加载状态枚举
 */
UENUM()
enum class EContextEffectsLibraryLoadState : uint8 {
	Unloaded = 0, // 未加载
	Loading = 1, // 加载中
	Loaded = 2 // 已加载
};

/**
 * Lyra上下文效果结构体
 */
USTRUCT(BlueprintType)
struct FLyraContextEffects
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadOnly)
	FGameplayTag EffectTag; // 效果标签

	UPROPERTY(EditAnywhere, BlueprintReadOnly)
	FGameplayTagContainer Context; // 上下文

	UPROPERTY(EditAnywhere, BlueprintReadOnly, meta = (AllowedClasses = "/Script/Engine.SoundBase, /Script/Niagara.NiagaraSystem"))
	TArray<FSoftObjectPath> Effects; // 效果数组（软对象路径）

};

/**
 * Lyra活动上下文效果类
 */
UCLASS(MinimalAPI)
class ULyraActiveContextEffects : public UObject
{
	GENERATED_BODY()

public:
	UPROPERTY(VisibleAnywhere)
	FGameplayTag EffectTag; // 效果标签

	UPROPERTY(VisibleAnywhere)
	FGameplayTagContainer Context; // 上下文

	UPROPERTY(VisibleAnywhere)
	TArray<TObjectPtr<USoundBase>> Sounds; // 声音数组

	UPROPERTY(VisibleAnywhere)
	TArray<TObjectPtr<UNiagaraSystem>> NiagaraSystems; // Niagara系统数组
};

/**
 * Lyra上下文效果库加载完成委托
 */
DECLARE_DYNAMIC_DELEGATE_OneParam(FLyraContextEffectLibraryLoadingComplete, TArray<ULyraActiveContextEffects*>, LyraActiveContextEffects);

/**
 * Lyra上下文效果库类
 */
UCLASS(MinimalAPI, BlueprintType)
class ULyraContextEffectsLibrary : public UObject
{
	GENERATED_BODY()
	
public:

	UPROPERTY(EditAnywhere, BlueprintReadOnly)
	TArray<FLyraContextEffects> ContextEffects; // 上下文效果数组

	/**
	 * 获取效果
	 */
	UFUNCTION(BlueprintCallable)
	UE_API void GetEffects(const FGameplayTag Effect, const FGameplayTagContainer Context, TArray<USoundBase*>& Sounds, TArray<UNiagaraSystem*>& NiagaraSystems);

	/**
	 * 加载效果
	 */
	UFUNCTION(BlueprintCallable)
	UE_API void LoadEffects();

	/**
	 * 获取上下文效果库加载状态
	 */
	UE_API EContextEffectsLibraryLoadState GetContextEffectsLibraryLoadState();

private:
	void LoadEffectsInternal(); // 内部加载效果

	void LyraContextEffectLibraryLoadingComplete(TArray<ULyraActiveContextEffects*> LyraActiveContextEffects); // Lyra上下文效果库加载完成

	UPROPERTY(Transient)
	TArray< TObjectPtr<ULyraActiveContextEffects>> ActiveContextEffects; // 活动上下文效果数组

	UPROPERTY(Transient)
	EContextEffectsLibraryLoadState EffectsLoadState = EContextEffectsLibraryLoadState::Unloaded; // 效果加载状态
};

#undef UE_API